package com.tiiime.bluetooth;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.UUID;

import com.bloodpressure.BloodPressureActivity;
import com.heartbeat.HeartBeatActivity;
import com.temperature.TemperatureActivity;

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class Main extends Activity{
	BluetoothAdapter btAdapter;
	BluetoothSocket btSocket;
	BluetoothDevice btDevice;
	OutputStream btOutputStream;
	InputStream btInputStream;
	private static Data data=null;
	private Button btn;
	private Button btn1,btn2;
	String bt_mac;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);



		btn=(Button)findViewById(R.id.button1);
		btn1=(Button)findViewById(R.id.button2);
		btn2=(Button)findViewById(R.id.button3);
		btn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent intent = new Intent();
				intent.setClass(Main.this,TemperatureActivity.class);
				startActivity(intent);

			}
		});

		btn1.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent intent = new Intent();
				intent.setClass(Main.this,BloodPressureActivity.class);
				startActivity(intent);

			}
		});

		btn2.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent intent = new Intent();
				intent.setClass(Main.this,HeartBeatActivity.class);
				startActivity(intent);

			}
		});

		//		new Thread(){
		//			public void run() {
		//				while (1>0) {
		//
		//					try {
		//						sleep(500);
		//					} catch (InterruptedException e) {
		//						// TODO Auto-generated catch block
		//						e.printStackTrace();
		//					}
		//					btAdapter = BluetoothAdapter.getDefaultAdapter();
		//					Intent intent = getIntent();
		//					bt_mac = intent.getStringExtra("dev_mac");
		//					btDevice = btAdapter.getRemoteDevice(bt_mac);
		//					connectBT();
		//					byte bytes[]=new byte[100];
		//					try {
		//						btInputStream.read(bytes);
		//					} catch (IOException e) {
		//						// TODO Auto-generated catch block
		//						e.printStackTrace();
		//					}
		//					String a=bytes.toString();
		//					DataContainer.get().setBP(Double.valueOf(a));
		//				}
		//			};	
		//		}.start();
	}
	//	void connectBT(){
	//		try{
	//			UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); //Standard SerialPortService ID
	//			btSocket = btDevice.createInsecureRfcommSocketToServiceRecord(uuid);
	//			btSocket.connect();
	//			btOutputStream = btSocket.getOutputStream();
	//			btInputStream = btSocket.getInputStream();
	//			//            btnConnect.setText(R.string.disconnect);
	//			System.out.println("connecting...");
	//		}
	//		catch(IOException ex)
	//		{
	//			Toast.makeText(this, "R.string.bluetooth_connection_failed", Toast.LENGTH_LONG).show();
	//			//	            btnConnect.setText(R.string.connect);
	//			try {
	//				btSocket.close();
	//			} catch (IOException closeException) {
	//
	//			}
	//			return;                        
	//		}
	//	}
	void closeBT() throws IOException
	{
		btOutputStream.close();
		btInputStream.close();
		btSocket.close();
	}
}
